﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BLevy.UI
{
    public partial class frmServiciosPorSocioReporteFiltro : Form
    {
        public frmServiciosPorSocioReporteFiltro()
        {
            InitializeComponent();
        }

        private void IniciarControles()
        {
            txtNroCertificado.Enabled = false;
            dtpDesde.Enabled = false;
            dtpHasta.Enabled = false;

            chkCompleto.CheckState = CheckState.Checked;
        }

        private void frmServiciosPorSocioReporteFiltro_Load(object sender, EventArgs e)
        {
            IniciarControles();
        }

        private void chkCertificado_CheckedChanged(object sender, EventArgs e)
        {
            if (chkCertificado.CheckState == CheckState.Checked)
            {
                txtNroCertificado.Enabled = true;
                chkCompleto.CheckState = CheckState.Unchecked;
            }
            else
            {
                txtNroCertificado.Enabled = false;
            }
        }

        private void chkFechas_CheckedChanged(object sender, EventArgs e)
        {
            if(chkFechas.CheckState == CheckState.Checked)
            {
                dtpDesde.Enabled = true;
                dtpHasta.Enabled = true;
                chkCompleto.CheckState = CheckState.Unchecked;
            }
            else
            {
                dtpDesde.Enabled = false;
                dtpHasta.Enabled = false;
            }
        }

        private void chkCompleto_CheckedChanged(object sender, EventArgs e)
        {
            if(chkCompleto.CheckState == CheckState.Checked)
            {
                chkCertificado.CheckState = CheckState.Unchecked;
                chkFechas.CheckState = CheckState.Unchecked;
                txtNroCertificado.Text = string.Empty;
            }
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            bool completo = chkCompleto.Checked;
            string numero_certificado = txtNroCertificado.Text == string.Empty ? null : txtNroCertificado.Text;
            DateTime? fecha_desde = chkFechas.Checked ? (DateTime?)dtpDesde.Value : null;
            DateTime? fechas_hasta = chkFechas.Checked ? (DateTime?)dtpHasta.Value : null;

            frmServiciosPorSocioReporte frm = new frmServiciosPorSocioReporte(completo, numero_certificado, fecha_desde, fechas_hasta);
            frm.MdiParent = this.MdiParent;
            frm.Show();

            this.Close();
        }
    }
}
